package com.itheima.request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;

@WebServlet("/params")
public class RequestParamtersServlet extends HttpServlet {
    /*
    request.getParameter(键名)  根据请求参数的名字 获取对应的值
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       // 在这里处理 因为是post请求

        // 只有post请求才有中文乱码 get没有
        request.setCharacterEncoding("utf-8");

        //数据是键值对 所以可以根据键找值
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String sex = request.getParameter("sex");
        String city = request.getParameter("city");
        String[] hobby = request.getParameterValues("hobby");
        String info = request.getParameter("info");

        System.out.println("username:"+username);
        System.out.println("password:"+password);
        System.out.println("sex:"+sex);
        System.out.println("city:"+city);
        System.out.println("hobby:"+ Arrays.toString(hobby));
        System.out.println("info:"+info);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
